package ute.tlcn.struts2hibernate.service;

import java.util.List;

import ute.tlcn.struts2hibernate.dao.HibernateUtil;
import ute.tlcn.struts2hibernate.dao.ItemDAO;
import ute.tlcn.struts2hibernate.dao.ItemDAOImpl;
import ute.tlcn.struts2hibernate.javabean.Item;

public class ItemBOImpl implements ItemBO {
	
	private ItemDAO dao = new ItemDAOImpl();
	
	@Override
	public void insert(Item item) throws Exception {
		dao.insert(item);
	}

	@Override
	public void delete(Integer itemId) throws Exception {
		dao.delete(itemId);
	}

	@Override
	public void update(Item item) throws Exception {
		dao.update(item);
	}

	@Override
	public List<Item> list() throws Exception {
		return dao.list();
	}

	@Override
	public Item findById(Integer itemId) throws Exception {
		return dao.findById(itemId);
	}
	
	public static void main(String[] args) throws Exception {
		HibernateUtil.getSesisonFactory().getCurrentSession().beginTransaction();
		ItemBO bo = new ItemBOImpl();
		List<Item> items = bo.list();
		for(Item i : items) {
			System.out.println(i.getName());
		}
		
		/*Item i = bo.findById(6);
		System.out.println(i.getName());*/
		
		HibernateUtil.getSesisonFactory().getCurrentSession().getTransaction().commit();
		HibernateUtil.close();
	}
}
